package izzat.fit.dbservice.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import izzat.fit.dbservice.base.entity.BaseEntity;
import izzat.fit.dbservice.base.mapper.BaseMapper;
import izzat.fit.dbservice.entity.action.Action;
import izzat.fit.dbservice.entity.mine.User;
import izzat.fit.dbservice.entity.training.ActionSet;
import izzat.fit.dbservice.entity.training.Plan;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @InterfaceName: TrainingMapper
 * @Description:
 * @Author: Izzat
 * @Date: 2019-12-29 17:46
 * @Version
 */
@DS(value = "fit_training_db")
@Mapper
public interface TrainingMapper extends BaseMapper {
    @Select("SELECT * FROM plan")
    List<Plan> getAllPlan();

    @Select("SELECT * FROM plan WHERE id = #{id}")
    Plan findPlanById(Integer id);

    @Select("SELECT * FROM plan WHERE creator = #{creator}")
    List<Plan> findPlanByCreator(Integer id);

    @Select("SELECT * FROM actionset WHERE plan = #{plan}")
    List<ActionSet> findActionSetByPlanId(Integer plan);


    @Insert("INSERT INTO actionset (plan, action, times, intensity) " +
            "VALUES (#{plan}, #{action}, #{times}, #{intensity})")
    int addActionSet(ActionSet actionSet);

    @Insert("INSERT INTO plan (creator, name, introduce, breaktime, type, part, cover) " +
            "VALUES (#{creator}, #{name}, #{introduce}, #{breaktime}, #{type}, #{part}, #{cover})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    int addPlan(Plan plan);

    @Delete({
            "<script>",
            "delete",
            "from plan",
            "where id in",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    Integer deletePlanById(@Param("ids") int[] array);
}
